package com.rongcheng.fortestlist.EXELFrameworkDemo.utils;

import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.AnswerQuestionFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.ClassifyQuestionFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.ClozeFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.MultiTypeQuestion.AnswerMultiQuestionFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.MultiTypeQuestion.ClozeMultiQuestionFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.MultiTypeQuestion.ListenMultiQuestionFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.SingleTypeQuestion.ConnectQuestionFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.FillBlankFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.SingleTypeQuestion.JudgeQuestionFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.ListenQuestionFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.SingleTypeQuestion.MultiChoicesFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.QABaseFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.fragment.SingleTypeQuestion.SingleChoiceFragment;
import com.rongcheng.fortestlist.EXELFrameworkDemo.model.QANode;

/**
 * @author frc
 *         created at 17-1-4.
 */

public class FragmentCreator {
    private static FragmentCreator instance;

    public static FragmentCreator getInstance() {
        if (instance == null) {
            instance = new FragmentCreator();
        }
        return instance;
    }

    public QABaseFragment createFragment(QANode node) {
        QABaseFragment qaBaseFragment = null;
        switch (node.mTemplate) {
            case EXELContaint.SINGLE_CHOICES:
                qaBaseFragment = new SingleChoiceFragment();
                break;
            case EXELContaint.MULTI_CHOICES:
                qaBaseFragment = new MultiChoicesFragment();
                break;
            case EXELContaint.FILL_BLANK:
                qaBaseFragment = new FillBlankFragment();
                break;
            case EXELContaint.NEW_FILL_BLANK:
                qaBaseFragment = new FillBlankFragment();
                break;
            case EXELContaint.JUDGE_QUESTION:
                qaBaseFragment = new JudgeQuestionFragment();
                break;
            case EXELContaint.CONNECT_QUESTION:
                qaBaseFragment = new ConnectQuestionFragment();
                break;
            case EXELContaint.CLASSIFY_QUESTION:
                qaBaseFragment = new ClassifyQuestionFragment();
                break;
            case EXELContaint.ANSWER_QUESTION:
                qaBaseFragment = new AnswerQuestionFragment();
                break;

            case EXELContaint.CLOZE_QUESTION:
                qaBaseFragment = new ClozeFragment();
                break;
            case EXELContaint.LISTEN_QUESTION:
                qaBaseFragment = new ListenQuestionFragment();
                break;
            case EXELContaint.MULTI_QUESTION:
                switch (node.mType) {
                    case EXELContaint.CLOZE_QUESTION:
                        qaBaseFragment = new ClozeMultiQuestionFragment();
                        break;
                    case EXELContaint.LISTEN_QUESTION:
                        qaBaseFragment = new ListenMultiQuestionFragment();
                        break;
                    case EXELContaint.ANSWER_QUESTION:
                        qaBaseFragment = new AnswerMultiQuestionFragment();
                        break;
                }
                break;
            default:
                try {
                    throw new ClassNotFoundException("没有该类型Fragment");
                } catch (Exception e) {
                    e.printStackTrace();
                }
        }
        return qaBaseFragment;
    }

}
